<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <title>收货地址管理</title>
    <link type="image/x-icon" rel="shortcut icon" href="../images/favicon.ico">
    <link rel="stylesheet" href="../res/mui/css/mui.min.css" />
    <link rel="stylesheet" href="../res/fontAwesome/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/user.css" />
    <style>
        * { touch-action: none; }
    </style>
</head>

<body>
    <div class="cz_layout bgg">
        <header class="cz_topBar">
            <a href="javascript:history.back();" class="icon_back fa fa-arrow-left"></a>
            <span class="title">收货地址管理</span>
        </header>
        <div class="cz_container">
            <ul class="mui-table-view">


            </ul>
            <a href="/user/addressManage.html" class="mui-btn mui-btn-primary btn_login">添加地址</a>
        </div>
        <footer class="cz_tabs">
            <a class="tab_home fa fa-home" href="../index.html"><span>首页</span></a>
            <a class="tab_cate fa fa-bars" href="../cate.html"><span>分类</span></a>
            <a class="tab_cart fa fa-shopping-cart" href="../cart.html"><span>购物车</span></a>
            <a class="tab_user fa fa-user" href="../user/index.html"><span>会员中心</span></a>
        </footer>
    </div>
    <script src="../res/mui/js/mui.min.js"></script>
    <script src="/assets/vendors/jquery/jquery.min.js"></script>
    <script src="/assets/vendors/template-web.js"></script>
    <script src="/assets/vendors/nprogress/nprogress.js"></script>
    <script src="/assets/vendors/layer/layer.js"></script>
    <script type="text/template" id="tpl">
        {{each lists value}}
            <input type="hidden" value="{{value.id}}" id="del">
            <li class="mui-table-view-cell">
                <div class="mui-slider-right mui-disabled">
                    <a class="mui-btn mui-btn-red">删除</a>
                </div>
                <a href="editAddress.html?id={{value.id}}" class="mui-navigate-right mui-slider-handle">
                    <div class="delivery">邮编：<span>{{value.postCode}}</span>&nbsp;收货人：<span>{{value.recipients}}</span></div>
                    <div class="address">{{value.address}}</div>
                </a>
            </li>
        {{/each}}
    </script>
    <script>
        $.ajax({
            url: '/api/address/queryAddress',
            type: 'get',
            success: function (msg) {
                if (msg.error) return location.href = '/user/login.html?url=' + location.href;
                strHtml = template('tpl', {
                    lists: msg
                });
                // console.log
                $('ul.mui-table-view').html(strHtml);
            }
        });
        $('.mui-table-view').on('click', '.mui-btn-red', function () {
            // alert(1)
            // var id = $('#del').val();
            var id = $(this).parent().parent().prev().val();
            console.log(id)
            $.ajax({
                url: '/api/address/deleteAddress',
                type: 'post',
                data: {
                    id: id
                },
                success: function (msg) {
                    if (msg.success) {
                        layer.msg('删除成功', {
                            shift: 5,
                            time: 500
                        }, function () {
                            location.reload();
                        })
                    }
                }
            });
        })
    </script>
</body>

</html>